package edu.iscas.appcheckclient.model;

public class Selector {

    protected String className;
    protected Selector.Type type;
    protected String value;
    public enum Type{
        BestEffort, ResourceID, Text, ContentDesc, Hint, XPath
    }

    public Selector(Type type, String className , String value) {
        this.className = className;
        this.type = type;
        this.value = value;
    }

    public String brewStatement(boolean isId){
        String str;
        switch(this.type){
            case ResourceID:
                str = "";
                if(this.value.startsWith("android.R.id")){
                    str = "withId(" + this.value + ")";
                }else{
                    str = "withId(\"" + this.value + "\")";
                }
                if(this.value.equals("android.R.id.zoomOut")) {
                    return "withId(\"" + this.value + "\")";
                }
                if(this.value.equals("android.R.id.zoomIn")) {
                    return "withId(\"" + this.value + "\")";
                }
                if(this.value.equals("android.R.id.select_dialog_listview")) {
                    return "withId(\"" + this.value + "\")";
                }
                if(this.value.equals("android.R.id.action_bar_title")) {
                    return "withId(\"" + this.value + "\")";
                }
                if(this.value.equals("android.R.id.alertTitle")) {
                    return "withId(\"" + this.value + "\")";
                }else{
                    return str;
                }
            case ContentDesc:
                return "withContentDescription(\"" + this.value + "\")";
            case Hint:
                return "withHint(\"" + this.value + "\")";
            case Text:
                return "withText(\"" + this.value + "\")";
        }
        return "withXPath(\"" + this.value + "\")";
    }

    public boolean equals(Object paramObject) {
        if(!(paramObject instanceof Selector))
            return false;
        else{
            Selector object = (Selector)paramObject;
            if((!this.type.equals(object.type)) || (!this.className.equals(object.className)) || (!this.value.equals(object.value))){
                return false;
            }
            return true;
        }
    }

    public Type getType() {
        return type;
    }

    public void setType(Type type) {
        this.type = type;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public String getClassName() {
        return className;
    }

    public void setClassName(String className) {
        this.className = className;
    }
}
